<template>
	<upper-navigation>寻根结果</upper-navigation>
	<view id="root-search-result">
		<view class="main-content">
			<view class="search-bar">
				<view class="search-title">
					您的检索
				</view>
				<view class="search-content">
					<input v-model="searchName" class="content" placeholder="输入查询姓名" />
					<view class="re-search" @click="search()">
						重新检索
					</view>
				</view>
			</view>
			<view class="title">
				检索结果:
			</view>
			<view class="search-result" v-if="result.isSuccess">
				<view class="desc">
					<view class="item" >
						《 {{ result.data.Genealogy }} 》
					</view>
					<view class="item" >
						{{ result.data.Audience }}
					</view>
					<view class="item-lower">
						<view class="left">
							一世祖{{ result.data.Level !== 1 ? result.data.Parents[0].Name : ''}}
						</view>
						<view class="right">
							林氏第{{ intToChinese(result.data.Level) }}世
						</view>
					</view>
				</view>
				<view class="root-container" :class="{ 'no-padding' : result.data.Level === 1}">
					<view class="root">
						<view v-for=" (item, index) in result.data.Parents" class="text" :key="index">
							第{{ intToChinese(item.Level) }}世:{{ item.Name }}
						</view>
					</view>
				</view>
			</view>

			<view class="search-result" v-else>
				<view class="desc">
					<view class="item">
						对不起,检索内容超出族谱数据服务
					</view>
					<view class="item">
						请重新输入
					</view>
				</view>
			</view>
		</view>
		<image :src="domain + '/static/Community/rootBackImg.png'" class="bg-img"></image>
	</view>
	<bottom-bar></bottom-bar>
</template>

<script setup>
	//姚珅 @ 5月13日 页面
	//姚珅 @ 5月18日 顶部底部导航组件添加
	import { domain } from '../../stores/useApp.js'
	import bottomBar from './bottomNavigationBar.vue'
	import upperNavigation from './upperNavigation.vue'
	import { onLoad } from "@dcloudio/uni-app";
	import { ref, reactive } from 'vue'
	import { intToChinese } from '../../common/numberConvert.js'
	const searchName = ref('');
	const result = reactive({
		isSuccess: false,
		data: {}
	});
	onLoad((option) => {
		searchName.value = option.name;
		search ();
	})
	async function search () {
		let msg = await uni.post("/uc/genealogy/Find", {
			name: searchName.value
		});
		result.isSuccess = msg.success;
		result.data = msg.data;
	}
</script>

<style lang="less">
	@import url(./shared.less);
	@search-size: 35rpx;
	@result-title-size: 40rpx;
	@result-desc-size: 30rpx;
	@bg-color: #EBF3F8;
	#root-search-result {
		.main-content {
			padding: 20rpx 55rpx;
			.search-bar {
				display: flex;
				// 字体大小以及居中
				font-size: @search-size;
				height: 2*@search-size;
				line-height: 2*@search-size;
				.search-title { 
					color: #505050;
				}
				.search-content {
					flex: 1;
					margin-left: 10rpx;
					background-color: @bg-color;
					border-radius: 20rpx;
					display: flex;
					overflow: hidden;
					.content {
						flex: 1;
						height: 2*@search-size;
						padding: 0 40rpx;
					}
					.re-search {
						padding: 0 40rpx;
						color: #fff;
						background: url("https://www.lin-home.com/static/Community/searchAgainBg.jpg") 50% 50% / cover;
						cursor: pointer;
						&:active {
							background-color: rgba(0, 0, 0, 0.1);
							opacity:0.7;
						}
					}
				}
			}
			.title {
				margin-top: 70rpx;
				font-size: @result-title-size;
			}
			.search-result {
				.desc {
					margin: 35rpx 0;
					font-size: @result-desc-size;
					line-height: 100rpx;
					color: #fff;
					.item {
						height: 100rpx;
						border-radius: 25rpx;
						background: url("https://www.lin-home.com/static/Community/rootResultBg.jpg") 50% 50% / cover;
						padding: 0 30rpx;
						margin: 20rpx 0;
					}
					.item-lower {
						display: flex;
						height: 100rpx;
						margin: 20rpx 0;
						.left {
							flex: 1;
							padding: 0 30rpx;
							margin-right: 20rpx;
							border-radius: 25rpx;
							background: url("https://www.lin-home.com/static/Community/rootResultBg.jpg") 0 50% / cover;
						}
						.right {
							flex: 1;
							padding: 0 30rpx;
							border-radius: 25rpx;
							background: url("https://www.lin-home.com/static/Community/rootResultBg.jpg") 100% 50% / cover;		
						}
					}
					
				}
				.root-container {
					background-color: #EBF3F8;
					border-radius: 25rpx;
					padding: 35rpx 20rpx;
					.root {
						background-color: #fff;
						padding: 20rpx;
						box-sizing: border-box;
						.text {
							font-size: 36rpx;
							line-height: 1.5;
						}
					}
				}
				.no-padding {
					padding: 0;
				}
			}
		}
		.bg-img {
			position: absolute;
			bottom: 100rpx;
			left: 200rpx;
			z-index: -1;
		}
	}
</style>